package com.scuec.tourismwebsite.controller;

import com.github.pagehelper.PageInfo;
import com.scuec.tourismwebsite.entity.FreeformPost;
import com.scuec.tourismwebsite.service.FreeformPostService;
import com.scuec.tourismwebsite.vo.AdminPost;
import com.scuec.tourismwebsite.vo.UserPost;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("tour/v1")
public class FreeformPostController {
    @Autowired
    private FreeformPostService freeformPostService;

    @GetMapping("Apostpages")
    public PageInfo<AdminPost> findAdminPostPages(Integer pageNum, Integer pageSize){
        return freeformPostService.findAdminPostPages(pageNum, pageSize);
    }

    @GetMapping("Apost")
    public List<AdminPost> findAPostAll(){
        return freeformPostService.findAPostAll();
    }

    @GetMapping("Apostpage")
    public PageInfo<AdminPost> findAdminPostPage(String username, Integer pageNum, Integer pageSize){
        return freeformPostService.findAdminPostPage(username, pageNum, pageSize);
    }

    @DeleteMapping("Apost/{post_id}")
    public Integer deleteAPostById(@PathVariable("post_id") int post_id){
        return freeformPostService.deleteAPostById(post_id);
    }

    @PutMapping("Apost/{post_id}/{comments_count}/{likes_count}/{collect_counts}")
    public Integer updateAPostCount(@PathVariable("post_id") Integer post_id, @PathVariable("comments_count") Integer comments_count, @PathVariable("likes_count") Integer likes_count, @PathVariable("collect_counts") Integer collect_counts){
        return freeformPostService.updateAPostCount(post_id, comments_count,likes_count,collect_counts);
    }

    @GetMapping("Apost/{post_id}")
    public AdminPost findAPostById(@PathVariable("post_id") Integer post_id){
        return freeformPostService.findAPostById(post_id);
    }

    @PostMapping("Apost")
    public Integer addAPost(@RequestBody FreeformPost freeformPost){
        return freeformPostService.insertPost(freeformPost);
    }
}
